// test-api.js
import axios from 'axios';

async function testAPI() {
  const baseURL = 'http://localhost:3000';
  
  try {
    // 测试默认路由
    console.log('Testing default route...');
    const homeResponse = await axios.get(baseURL);
    console.log('Home response:', homeResponse.data);
    
    // 测试注册接口
    console.log('\nTesting register...');
    const registerResponse = await axios.post(`${baseURL}/api/v1/register`, {
      username: 'testuser',
      email: 'test@example.com',
      password: '123456'
    });
    console.log('Register response:', registerResponse.data);
    
    // 如果注册成功，测试登录接口
    if (registerResponse.data.success) {
      console.log('\nTesting login...');
      const loginResponse = await axios.post(`${baseURL}/api/v1/login`, {
        username: 'testuser',
        password: '123456'
      });
      console.log('Login response:', loginResponse.data);
    }
  } catch (error) {
    console.error('API Test Error:', error.response ? error.response.data : error.message);
  }
}

testAPI();